Page({
  data: {
    fileList: [],list:[],goods_id:'',url1:'',value:1,speclist:[],a:'3',b:'5',c:'14',tijiao_id:"",file:''
  },
 
  onLoad(options){
    this.setData({
      goods_id:options.id
    })
    this.getrulelist()
  },
  
  
  
  
  
  
  
  
  
  afterRead(event) {
    const { file } = event.detail;
    console.log(file);
    this.setData({
      file:file.path
    })
    const that=this
      
    
    
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
    wx.uploadFile({
      
      url: 'https://zujieba.com/Api/upload/upload', // 仅为示例，非真实的接口地址
      filePath: file.path,
      name:'file',
      
      success(res) {
        
        const res1=JSON.parse(res.data).name
        const array=[]
        array.push(res1)
        that.setData({
          list:array
        })
        
        
        
        console.log(res1);
        const url1="https://zujieba.com/uploads/"+res1
        
        console.log(url1);
        
        const fileList=[]
        const object={}
        object.url=url1
        object.name=2
        object.deletable=true
        
       fileList.push(object) 
        that.setData({ fileList ,url1});
      }
      
    });
  },
  deleteclick(e){
    const index=  e.detail.index
    const list=this.data.fileList
        list.splice(index,1)
       this.setData({
         fileList:list
       })
           
         
    },
    //单选框纸张大小
    onchange(e){
  console.log(e);
  var that=this
  console.log(that.data.speclist);
  
     
     if(e.currentTarget.dataset.index==0){
        that.setData({
           a:e.detail.value
        })
        
     }else{
       if(e.currentTarget.dataset.index==1){
         that.setData({
           b:e.detail.value
         })
       }else{that.setData({
         c:e.detail.value
       })}
     }   
    },
    getrulelist(){
      wx.request({
        url: 'https://zujieba.com/Api/spec/spec',
        data:{id:this.data.goods_id},
        success:(res)=>{
        console.log(res);
        const speclist=res.data.data.spec
        this.setData({
          speclist
        })
        console.log(this.data.speclist);
        
        
        }
      })
    },

    //编辑图片
    editclick(){
      wx.navigateTo({
        url:"/pages/edit/edit?url="+this.data.file
      })
      
    },
    //提交订单
    orderclick(){
      var that=this
      const uid=wx.getStorageSync('uid')
      const selectid=that.data.a+'_'+that.data.b+"_"+that.data.c
      console.log(selectid);
      
      const type=that.data.value
      const params={goods_id:that.data.goods_id,spec_id:selectid,uid,file:that.data.url1}
      console.log(params);
      
      wx.request({
        url: 'https://zujieba.com/Api/car/add_car.html',
        data:params,
        success:(res)=>{
          const tijiao_id=res.data.data
        that.setData({
          tijiao_id
        })
          console.log(res);
         
          if(res.data.success==2){
            wx.showToast({
              title: res.data.tips,
              icon:'none'
            })
          }else{
            wx.navigateTo({
              url: '/pages/order/order?id='+this.data.tijiao_id,
            })
          }
          
             
        }
       /* success:(res)=>{
          console.log(res);
          
          const address=res.data.data.address.province+res.data.data.address.city+res.data.data.address.area
          console.log(address);
          
            wx.navigateTo({
              url: '/pages/order/order?address='+address+"&goods_id="+this.data.goods_id+'&id='+this.data.selectid+"&name="+res.data.data.address.name+'&phone='+
              res.data.data.address.phone+'&image='+this.data.url1
            })
          
        }*/
      })
    },
    onchange1(e){
      this.setData({
        value:e.detail
      })
      
       
    }
});